package com.briup.cms.service.impl;


import com.briup.cms.bean.Category;
import com.briup.cms.dao.CategoryMapper;
import com.briup.cms.dao.extend.ArticleExtendMapper;
import com.briup.cms.dao.extend.CategoryExtendMapper;
import com.briup.cms.exception.CustomerException;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.utils.MessageStatus;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategorySercviceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper mapper;
    @Autowired
    private CategoryExtendMapper categoryExtendMapper;
    @Autowired
    private ArticleExtendMapper articleExtendMapper;


    public PageInfo<Category> pageAll(int paramInt1, int paramInt2) {
        PageHelper.startPage(paramInt1, paramInt2, true);
        List<Category> list = categoryExtendMapper.pageAll();

        return new PageInfo(list);

    }

    public void insert(Category record) {
        mapper.insert(record);

    }

    public void batchdelete(int[] ids) {


        for (int id : ids) {
            articleExtendMapper.deleteArticleByCategoryId(id);
            mapper.deleteByPrimaryKey(id);

        }
    }


    public List<Category> findall() {
        List<Category> list = categoryExtendMapper.findAll();
        return list;

    }

    public void deleteByPrimaryKey(Integer categoryId) {

        mapper.deleteByPrimaryKey(categoryId);

    }

    public void updateByPrimaryKey(Category record) {
        mapper.updateByPrimaryKey(record);

    }
}





